# 设计一个类，用来表示一个学生
# class Student():
#     name = None  # 成员变量
#     gender = None
#     nationality = None
#     age = None
#     __op="私有成员"
#     def __ops(self):
#         print(f"私有成员方法：{self.__op}")
#     def __init__(self, name, gende, nationality, age):
#         self.name = name
#         self.gender = gende
#         self.nationality = nationality
#         self.age=age
#         print(f"Student类创建构造方法,{self.name}")
#
#     def say_h(self):  # 写在类内部的函数：方法(成员方法)
#         print(f"hello,我是{self.name},现在年龄为{self.age},现居在{self.nationality}")
#
#     def say_h2(self, msg):
#         print(f"{self.name}说：{msg}{msg}")
#
#     def __str__(self):
#         return f"Stdent:name={self.name}"
#
#     def __lt__(self, other):
#         return self.age < other.age
#     def __le__(self, other):
#         return self.age <= other.age
#     def __eq__(self, other):
#         return self.name == other.name
#
#
# stdent_3 = Student("张四", "女", "中国", 20)
# stdent_2 = Student("张四", "男", "中国", 12)
# print(stdent_3.gender)
# print(f"__str__输出：{str(stdent_3)}")
# print(stdent_2 < stdent_3)
# print(stdent_2 > stdent_3)
# print(stdent_2 <= stdent_3)
# print(f"stdent_2 == stdent_3:{stdent_2 == stdent_3}")
# 创建一个对象
# stdent_1= Student()
# stdent_1.name="张三"
# stdent_1.gender="男"
# stdent_1.nationality="中国"
# stdent_1.age=18
#
# print(f"我是{stdent_1.name},现居在{stdent_1.nationality}")
#
# stdent_1.say_h()
# stdent_1.say_h2("你好")


# class User:
#     name=None
#     age=None
#     __op="私有成员"
#     def __init__(self,name,age):
#         self.name=name
#         self.age=age
#         print(f"User类创建构造方法,{self.name},{self.__op}")
#
# user=User("张三",18)


# 私有方法不能被外部调用
# class Person:
#     __name = None # 名称
#     def __countname(self):
#         return len(self.__name)
#     def setname(self,name):
#         self.__name = name
#     def getcountname(self):
#         return self.__countname()
#
# p1 = Person()
# p1.setname("张三")
# print(f"姓名长度：{p1.getcountname()}")
# # p1.__countname() # 报错，私有方法不能被外部调用


# 继承
# class Person:
#     def __init__(self,name,gender,nationality,age):
#         self.name=name
#         self.gender=gender
#         self.nationality=nationality
#         self.age=age
#     def say_h(self):
#         print(f"hello,我是{self.name},现在年龄为{self.age},现居在{self.nationality}")
#
# class Student(Person):
#     def __init__(self,name,gender,nationality,age,grade):
#         super().__init__(name,gender,nationality,age)
#         self.grade=grade
#     def say_h(self):
#         print(f"hello,我是{self.name},现在年龄为{self.age},现居在{self.nationality},我在读{self.grade}年级")
# s1=Student("张三","男","中国",18,"大一")
# s1.say_h()



# 继承
# class Person:
#     def say_h(self):
#         print("学生说：hello")
# class Student(Person):
#     pass
# s1 = Student()
# s1.say_h() # 输出：学生说：hello



# # 基础类型注解
# var1:int=10
# var2:str="hello"
# var3:float=3.14
# # 复杂类型注解
# var4:(int,str,float)=(10,"hello",3.14)
# var5:[int]=[1,2,3,4,5]
# var6:{str:int}={"name":10,"age":20}
# # 函数类型注解
# def add(a:int,b:int)->int:
#     return a+b
# # 类类型注解
# class Person:
#     name:str
#     age:int
#     def __init__(self,name:str,age:int)->None:
#         self.name=name
# # 使用注释进行类型注解
# def add2(a:int,b:int)->int:
#     # type: (int,int)->int
#     return a+b
# print(var1,var2,var3,var4,var5,var6,add(1,2),add2(1,2))




# 多态
# class Animal:
#     def eat(self):
#         pass
# # 定义子类
# class Dog(Animal):
#     def eat(self):
#         print("狗吃骨头")
# # 定义另一个子类
# class Cat(Animal):
#     def eat(self):
#         print("猫吃鱼")
# # 创建对象
# dog=Dog()
# cat=Cat()
# # 定义一个函数
# def eat_animal(animal:Animal):
#     animal.eat()
# # 调用函数
# eat_animal(dog) # 输出：狗吃骨头
# eat_animal(cat) # 输出：猫吃鱼